package com.cloudfun.campusshare.controller.miniprogram;

import com.cloudfun.campusshare.common.constant.Code;
import com.cloudfun.campusshare.common.constant.RoleType;
import com.cloudfun.campusshare.common.response.BaseResult;
import com.cloudfun.campusshare.common.response.BaseResultFactory;
import com.cloudfun.campusshare.common.security.AuthRequired;
import com.cloudfun.campusshare.common.security.AuthenticationHolder;
import com.cloudfun.campusshare.entity.WeChatContractEntity;
import com.cloudfun.campusshare.service.WeChatContractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Huqin on 2020/4/20
 */
@Slf4j
@RestController
@RequestMapping("/v1/wechat-contract")
@Api(value = "客户免密支付协议模块")
@AuthRequired(role = RoleType.CUSTOMER)
public class WeChatContractController {

    @Autowired
    private WeChatContractService weChatContractService;

    @ApiOperation(value = "获取免密支付信息", notes = "获取免密支付信息")
    @GetMapping
    public BaseResult<Boolean> contract() {
        WeChatContractEntity contractEntity = weChatContractService.getByCustomerId(AuthenticationHolder.getUserId());
        if (null != contractEntity) {
            return BaseResultFactory.produceResult(Code.SUCCESS, true);
        }
        return BaseResultFactory.produceResult(Code.SUCCESS, false);
    }

}
